23 #define D(x) cout << #x " is " << (x) << endl
25 typedef unsigned long long Int
;
26 const int BUFSIZE
= 256;
29 typedef bitset
<100> num
;
31 num
operator +(num a
, num b
){
39 bool end
; //is this node a complete prefix?
40 node(bool e
) : end(e
) {
45 //not used, because I love to waste memory (It makes me feel dangerous)
47 if (n
== NULL
) return;
48 clean(n
->left
); clean(n
->right
);
52 Int
f(string s
, node
* n
){ //s = string built so far, n = the node we are standing at
53 Int left
= 0, right
= 0;
55 left
= f(s
+ "0", n
->left
);
57 if (n
->right
!= NULL
){
58 right
= f(s
+ "1", n
->right
);
61 Int x
= ((1ULL) << (M
- s
.size())) - 1;
62 if (M
- s
.size() == 64){
65 ans
[s
] = x
- left
+ 1 - right
;
71 return ret
+ left
+ right
;
76 while (scanf("%d %d\n", &n
, &M
)==2 && !(n
== 0 && M
== 0)){
78 node
* root
= new node(true);
80 fgets(buf
, BUFSIZE
, stdin
);
88 if (cur
->left
== NULL
) cur
->left
= new node(false);
90 }else if (buf
[i
] == '1'){
91 if (cur
->right
== NULL
) cur
->right
= new node(false);
102 fgets(buf
, BUFSIZE
, stdin
);
103 buf
[strlen(buf
)-2] = '\0'; //delete *\n
104 Int t
= ans
[string(buf
)];
109 fgets(buf
, BUFSIZE
, stdin
); //empty line